<template>
    <z-form v-if="flag" url="/api/form/insertData" :params="params" lazy :fields="items" >
        </z-form>
</template>

<script>
export default {
    data() {
        return {
            items: [],
            flag: false,
        };
    },
    props: {
        params: Object,
    },
    async created() {
        const data = await $.get({
            url: "/api/form/create",
            data: { id: this.params.id },
        });
        this.items = this.rendering(data);
        this.flag = true;
    },
    methods: {
        rendering(data) {
            const typeMap = {
                input: "input",
                partner: "search",
                date: "date",
                number: "number",
                signature: "textarea",
                table: 'material',
            };
            return data.map((item) => ({
                label: item.label,
                name: item.id,
                type: typeMap[item.type],
                depend: item.type === 'partner' ? 'party' : '',
                tenant: true,
                default: item?.value || item?.default || '',
                tip: item?.desc || '',
                unit: item?.unit || '',
                multiple: item.type === 'table',
                // params: {
                //     contractId: this.params.id,
                // }
            }));
        },
    },
};
</script>

<style scoped></style>
